# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer:
pkgname=bear
pkgver=3.1.5
pkgrel=1
pkgdesc="Tool which generates a compilation database for clang tooling"
url="https://github.com/rizsotto/Bear"
# s390x: segfaults in check
arch="all !s390x"
license="GPL-3.0-or-later"
makedepends="
	abseil-cpp-dev
	c-ares-dev
	cmake
	fmt-dev
	grpc-dev
	gtest-dev
	nlohmann-json
	protobuf-dev
	re2-dev
	samurai
	spdlog-dev
	sqlite-dev
	"
checkdepends="llvm-test-utils"
subpackages="$pkgname-doc"
source="https://github.com/rizsotto/Bear/archive/$pkgver/bear-$pkgver.tar.gz"
builddir="$srcdir/Bear-$pkgver"

prepare() {
	default_prepare
	case "$CARCH" in
		x86) rm -f test/cases/intercept/preload/signal_outside_build.sh ;;
		riscv64) rm -f test/cases/intercept/preload/signal_outside_build.sh ;;
	esac
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_INSTALL_LIBEXECDIR=libexec/bear \
		-DCMAKE_BUILD_TYPE=MinSizeRel
	cmake --build build
}

check() {
	# XXX: Tests fail when ccache is enabled.
	# armv7, armhf and aarch64 have some failing tests.
	case "$CARCH" in
		armhf|armv7|aarch64|riscv64|s390x) _options="--show-only" ;;
		*) _options="--no-tests=ignore" ;;
	esac
	ctest --test-dir build --verbose --output-on-failure "$_options"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
acf233f7bb8215694734b6c947c965323c0a5ea0c2a6bbb210a37e38fdf545326ca8de3a7b31ce81469756afd1c02233775ddc5936fd04132f216def6e3ce1de  bear-3.1.5.tar.gz
"
